//
//  NRWBrandSeriesCell.m
//  NRWMall
//
//  Created by 邢毅 on 2018/5/23.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWBrandSeriesCell.h"

@implementation NRWBrandSeriesCell
{
    UIImageView *_iconImageView;
    UILabel *_titleLabel;
}

- (void)setTitleString:(NSString *)titleString {
    
    _titleString = titleString;
    
    _titleLabel.text = titleString;
}

- (void)setLogoString:(NSString *)logoString {
    
    _logoString = logoString;
    
    if ([logoString hasPrefix:@"http"]) {
        [_iconImageView sd_setImageWithURL:[NSURL URLWithString:logoString]];
    } else {
        _iconImageView.image = getImage(logoString);
    }
}

- (void)setDidSelected:(BOOL)didSelected {
    
    _didSelected = didSelected;
    
    _titleLabel.textColor = didSelected? mainColor(): mainFontColor();
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.layer.shouldRasterize = true;
        self.layer.rasterizationScale = UIScreen.mainScreen.scale;
        self.layer.drawsAsynchronously = true;
        self.separatorInset = UIEdgeInsetsZero;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    if (self.isSeriesCell) {
        _iconImageView.frame = CGRectMake(0, 0, 0, 0);
        _titleLabel.frame = CGRectMake(_iconImageView.viewMaxX + 16, 12, 250, 24);
    } else {
        _iconImageView.frame = CGRectMake(17, 12, 24, 24);
        _titleLabel.frame = CGRectMake(_iconImageView.viewMaxX + 16, 12, 250, 24);
    }
}

- (void)setupUI {
    
    _iconImageView = [[UIImageView alloc] init];
    _iconImageView.backgroundColor = [UIColor whiteColor];
    _iconImageView.opaque = YES;
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = getThemeFont(13);
    
    [self.contentView addSubview:_iconImageView];
    [self.contentView addSubview:_titleLabel];
}

@end
